
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:hxdj/common/routers/login_routers_manager.dart';

abstract class IRouterProvider{
  
  void initRouter(FluroRouter router);
}


class Routes {

  static final List<IRouterProvider> _listRouter = [];

  static final FluroRouter router = FluroRouter();

  static void initRoutes() {
  
    /// 指定路由跳转错误返回页
    router.notFoundHandler = Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
      return const NotFoundPage();
    });

    _listRouter.clear();

    //各自路由由各自模块管理，统一在此添加初始化
    _listRouter.add(LoginRouterManager());

    /// 初始化路由
    for (IRouterProvider routerProvider in _listRouter) {
      routerProvider.initRouter(router);
    }
  }
}




abstract class NavigatorJumpListener {
  Future<void> push(
    BuildContext context,
    String path, {
    bool replace = false,
    bool clearStack = false,
    TransitionType transition = TransitionType.cupertino,
  });

  void pushResult(
    BuildContext context,
    String path,
    Function(Object) function, {
    bool replace = false,
    bool clearStack = false,
    TransitionType transition = TransitionType.cupertino,
  });

  Future pushParams(BuildContext context, String path,
      {Map<String, dynamic> params,
      Object arguments,
      TransitionType transition = TransitionType.cupertino,
      bool replace = false,
      bool clearStack = false});
}




// 404 page
class NotFoundPage extends StatelessWidget {
  const NotFoundPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('404'),
        centerTitle: true,
      ),
        body:const Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
             SizedBox(
              width: double.infinity,
              height: 16,
            ),
            Text(
              "请升级最新版本,再次查看",
            ),
          ],
        )
    );
  }
}